package com.mail;

import com.alibaba.fastjson.JSONObject;
import exam.common.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/4/24 14:31
 * @since JDK 1.8
 */
@Api(tags = {"邮箱服务模块"})
@RestController
@RequestMapping("mail")
public class MailController {

    @Autowired
    private MailService mailService;

    @PostMapping("send")
    @ApiOperation("邮件发送")
    public JSONObject sendMail(@ApiParam("邮箱地址")@RequestParam("mail")String mail,
                               @ApiParam("邮件标题")@RequestParam("subject")String subject,
                               @ApiParam("邮件内容")@RequestParam("content")String content){
//        if(!VerifyUtils.isMail(mail)){
//            return Result.errorObject("请输入正确的邮箱格式");
//        };
        if(StringUtils.isEmpty(subject)||StringUtils.isEmpty(content)){
            return Result.errorObject("邮件或标题不得为空");
        }
        mailService.send(mail,subject,content);
        return Result.successObject("邮件发送成功");
    }




}
